/*
 * Copyright (c) 2007-2020 西安交通信息投资营运有限公司 版权所有
 */

package com.xci.edu.core.api;

import com.github.lvyanyang.annotation.Authorize;
import com.github.lvyanyang.core.BaseController;
import com.github.lvyanyang.core.BoolResult;
import com.github.lvyanyang.core.Const;
import com.github.lvyanyang.core.PageList;
import com.github.lvyanyang.core.XCI;
import com.xci.edu.core.entity.EduCategory;
import com.xci.edu.core.filter.EduCategoryFilter;
import com.xci.edu.core.service.EduCategoryService;
import com.github.lvyanyang.model.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperationSupport;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 培训科目信息接口
 * @author 张谦 zhangqian@xci96716.com
 * @since 2020-11-24 17:54:07
 */
@Api(tags = "培训科目信息接口")
@Authorize
@RestController
@RequestMapping(value = "/api/core/eduCategory", produces = Const.PROJSON)
public class EduCategoryApiController extends BaseController {
    /** 培训科目信息服务 */
    @Resource private EduCategoryService eduCategoryService;

    @ApiOperationSupport(order = 1)
    @ApiOperation(value = "新建培训科目信息")
    @Authorize(code = "core.eduCategory.insert")
    @PostMapping("/insert")
    public BoolResult insert(@RequestBody EduCategory entity) {
        return eduCategoryService.insert(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改培训科目信息")
    @Authorize(code = "core.eduCategory.update")
    @PostMapping("/update")
    public BoolResult update(@RequestBody EduCategory entity) {
        return eduCategoryService.update(entity);
    }

    @ApiOperationSupport(order = 2)
    @ApiOperation(value = "修改培训科目状态")
    @Authorize(code = "core.eduCategory.updateStatus")
    @PostMapping(value = "/updateStatus")
    public BoolResult updateStatus(@RequestBody IdsStatusBody body) {
        eduCategoryService.updateStatus(body.getIds(), body.getStatus());
        return BoolResult.success();
    }

    @ApiOperationSupport(order = 3)
    @ApiOperation(value = "根据主键字符串删除培训科目信息")
    @Authorize(code = "core.eduCategory.delete")
    @PostMapping(value = "/delete")
    public BoolResult delete(@RequestBody IdsBody body) {
        return eduCategoryService.delete(body.getIds());
    }

//    @ApiOperationSupport(order = 4)
//    @ApiOperation(value = "检查培训科目信息主键是否存在")
//    @PostMapping(value = "/existById")
//    public BoolResult existById(@RequestBody IdBody body) {
//        return BoolResult.success(eduCategoryService.existById(body.getId()));
//    }
//    @ApiOperationSupport(order = 5)
//    @ApiOperation(value = "检查培训科目信息名称是否存在")
//    @PostMapping(value = "/existByName")
//    public BoolResult existByName(@RequestBody NameExcludeIdBody body) {
//        return BoolResult.success(eduCategoryService.existByName(body.getName(), body.getExcludeId()));
//    }

    @ApiOperationSupport(order = 6)
    @ApiOperation(value = "根据主键查询单个培训科目信息")
    @Authorize(code = "core.eduCategory.select")
    @PostMapping("/selectById")
    public BoolResult<EduCategory> selectById(@RequestBody IdBody body) {
        return BoolResult.success(eduCategoryService.selectById(body.getId()));
    }

    @ApiOperationSupport(order = 7)
    @ApiOperation(value = "查询培训科目信息分页列表")
    @Authorize(code = "core.eduCategory.select")
    @PostMapping("/selectPageList")
    public BoolResult<PageList<EduCategory>> selectPageList(@RequestBody EduCategoryFilter filter) {
        return BoolResult.success(eduCategoryService.selectPageList(filter));
    }

    @ApiOperationSupport(order = 8, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "查询培训科目信息列表")
    @Authorize(code = "core.eduCategory.select")
    @PostMapping("/selectList")
    public BoolResult<List<EduCategory>> selectList(@RequestBody EduCategoryFilter filter) {
        return BoolResult.success(eduCategoryService.selectList(filter));
    }

    @ApiOperationSupport(order = 9, ignoreParameters = {Const.IPI, Const.IPS, Const.IPSN, Const.IPSD})
    @ApiOperation(value = "导出培训科目信息列表")
    @Authorize(code = "core.eduCategory.export")
    @PostMapping(value = "/export", produces = {Const.PROOCTET, Const.PROJSON})
    public void export(@RequestBody EduCategoryFilter filter) {
        XCI.exportExcel(eduCategoryService.selectList(filter), EduCategory.class, "培训科目信息列表");
    }

//    @ApiOperationSupport(order = 10)
//    @ApiOperation(value = "获取培训科目信息导出字段")
//    @PostMapping(value = "/exportNames")
//    public BoolResult<List<String>> exportNames() {
//        return BoolResult.success(XCI.getExcelFiledNames(EduCategory.class));
//    }
}